const webpack = require('webpack');
const path = require('path');

let config = {
    entry: {
        vendor_react: ['react', 'react-dom'],
        vendor_ant: ['antd'],
        index: path.resolve(__dirname, 'index.jsx')
    },
    resolve: {
        root: path.resolve('src'),
        extensions: ['', '.js', '.jsx']
    },
    output: {
        publicPath: '/build/',
        path: 'build',
        filename: '[name].bundle.js'
    },
    module: {
        preLoaders: [
            {
                test: /\.jsx?$/,
                loader: 'eslint-loader',
                include: [path.resolve(__dirname, 'src')],
                exclude: /node_modules/
            }
        ],
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                loader: ['babel'],
                query: { presets: ['es2015', 'react'] }
            },
            {
                test: /\.s?css$/,
                loaders: ['style-loader', 'css-loader?importLoaders=1', 'postcss-loader?parser=postcss-scss']
            },
            {
                test: /\.html$/,
                loaders: ['html-loader?minimize=true', 'file-loader?name=[path][name].[ext]', 'extract-loader']
            }
        ]
    },
    cache: true,
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin(),
        new CommonsChunkPlugin({
            name: 'vendor_react',
            filename: 'vendor_react.js',
            chunks: ['vendor_react']
        }),
        new CommonsChunkPlugin({
            name: 'vendor_antd',
            filename: 'vendor_antd.js',
            chunks: ['vendor_antd']
        }),
        new HtmlWebpackPlugin({
            title: 'My App',
            filename: 'app/www/index/index.html',
            template: 'app/www/index/index.html',
            inject: 'body',
            chunks: ['index', 'vendor_react', 'vendor_antd', 'vendor_hotserver']
        }),
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        })
    ]
}

module.exports = config;